//导入vue、vue-router
import Vue from 'vue'
import Router from 'vue-router'

//懒加载路由组件
const Home = () => import('views/home/Home.vue')
const Category = () => import('views/category/Category.vue')
const Cart = () => import('views/cart/Cart.vue')
const Profile = () => import('views/profile/Profile.vue')
const Detail = () => import('views/detail/Detail.vue')

//解决vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

//1.安装插件
Vue.use(Router)

//配置映射关系
const routes = [
	{
		path:'',
		redirect:'/home'
	},
	{
		path:'/home',
		component:Home
	},
	{
		path:'/category',
		component: Category
	},
	{
		path:'/cart',
		component: Cart
	},
	{
		path:'/profile',
		component: Profile
	},
	{
		path:'/detail/:id',
		component: Detail
	}
]

//2.创建router
const router = new Router({
	routes,
	mode: 'history'
})

//3.导出router
export default router

